package com.guozcc.bootweb.api.job;

import com.alibaba.fastjson.JSONObject;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Component
public class MyDataFlowJob implements DataflowJob<JSONObject> {
    @Override
    public List<JSONObject> fetchData(ShardingContext shardingContext) {
        log.info("；调度名称："+shardingContext.getJobName()
                +"；分片总数："+shardingContext.getShardingTotalCount()
                +"；当前分片键："+shardingContext.getShardingItem()
                +"；当前分片值："+shardingContext.getShardingParameter()
                +"调度参数："+shardingContext.getJobParameter()
        );

        return new ArrayList<JSONObject>(){{
            add(new JSONObject().fluentPut("name","guozichao"));
            add(new JSONObject().fluentPut("name","zhangsan"));
        }};
    }


    @Override
    public void processData(ShardingContext shardingContext, List<JSONObject> data) {
        log.info("处理数据数"+data.size());
    }
}
